<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>文件上传控件</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
    <link rel="stylesheet" href="../formdesign/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="../../../css/ueditor/site.css">
    <script type="text/javascript" src="../dialogs/internal.js"></script>
    <script type="text/javascript" src="../../../js/jquery/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="../../../js/base/base.js"></script>
    <script type="text/javascript">
        function createElement(type, name)
        {
            var element = null;
            try {
                element = document.createElement('<'+type+' name="'+name+'">');
            } catch (e) {}
            if(element==null) {
                element = document.createElement(type);
                element.name = name;
            }
            return element;
        }
    </script>
</head>
<body>
<div class="content">
    <table class="table table-bordered table-striped table-hover">
        <thead>
        <tr>
            <th><span>控件名称</span><span class="label label-important">*</span></th>
            <th><span>属性</span></th>
        </tr>
        <tr>
            <td >
                <input id="orgname" type="text" placeholder="必填项"/>
            </td>
            <td>
                宽 <input id="orgwidth" type="text" value="50" class="input-small span1" placeholder="auto"> px
                &nbsp;&nbsp;
                高 <input id="orgheight" type="text" value="50" class="input-small span1" placeholder="auto"> px
            </td>
        </tr>
        <tr>

        </tr>
        </thead>


    </table>
</div>
<script type="text/javascript">
    $(function () {
        var oNode = null,thePlugins = 'fileupload';
        var dataid = $.getQueryString('dataid');
        var dataNumber=parent.pluginId;

        if( UE.plugins[thePlugins].editdom ){
            oNode = UE.plugins[thePlugins].editdom;
            var gTitle=oNode.getAttribute('title').replace(/&quot;/g,"\"");
            var gWidth=oNode.getAttribute('width');
            var gHeight=oNode.getAttribute('height');
            $G('orgname').value = gTitle;
            $G('orgwidth').value = gWidth;
            $G('orgheight').value = gHeight;
        }
        dialog.oncancel = function () {
            if( UE.plugins[thePlugins].editdom ) {
                delete UE.plugins[thePlugins].editdom;
            }
        };
        dialog.onok = function (){
            if ( $G('orgname').value == '' ) {
                alert('控件名称不能为空');
                return false;
            }
            var gTitle=$G('orgname').value.replace(/\"/g,"&quot;"),orgwidth=$G('orgwidth').value,orgheight=$G('orgheight').value;
            if( !oNode ) {
                try {
                    oNode = createElement('img');
                    oNode.setAttribute('src','/img/fileupload.png');
                    oNode.setAttribute('class', "form_item fileupload");
                    oNode.setAttribute('data-type', "fileupload");
                    oNode.setAttribute('style', "cursor: pointer; margin: 0 5px;");
                    oNode.setAttribute('align', "absmiddle");
                    oNode.setAttribute('title',gTitle);
                    oNode.setAttribute('name','DATA_'+dataNumber);
                    oNode.setAttribute('id','DATA_'+dataNumber);
                    oNode.setAttribute('width',orgwidth);
                    oNode.setAttribute('height',orgheight);
                    editor.execCommand('insertHtml',oNode.outerHTML);
                    return true;
                } catch ( e ) {
                    try {
                        editor.execCommand('error');
                    } catch ( e ) {
                        alert(控件异常);
                    }
                    return false;
                }
            } else {
                var norgname = oNode.getAttribute('name').replace(/\"/g,"&quot;");
                var oNewNode = null;
                domUtils.remove(oNode,false);  //删除当前控件，再创建一个新的

                oNewNode = createElement('img');
                oNewNode.setAttribute('src','/img/icon_uploadimg.png');
                oNewNode.setAttribute('class', "form_item fileupload");
                oNewNode.setAttribute('data-type', "fileupload");
                oNewNode.setAttribute('style', "cursor: pointer;");
                oNode.setAttribute('align', "absmiddle");
                oNewNode.setAttribute('title',gTitle);
                oNewNode.setAttribute('name','DATA_'+dataid);
                oNewNode.setAttribute('id','DATA_'+dataid);
                oNewNode.setAttribute('width',orgwidth);
                oNewNode.setAttribute('height',orgheight);
                editor.execCommand('insertHtml',oNewNode.outerHTML);
                delete UE.plugins[thePlugins].editdom;
            }
        };

    });

</script>
</body>
</html>
